package com.xd.user.controller;


import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xd.common.base.BaseController;
import com.xd.common.model.R;
import com.xd.common.vo.Validity;
import com.xd.user.api.entity.Dict;
import com.xd.user.api.entity.DictData;
import com.xd.user.api.entity.Role;
import com.xd.user.api.feign.DictFeign;
import com.xd.user.api.feign.RoleFeign;
import com.xd.user.service.DictDataService;
import com.xd.user.service.DictService;
import com.xd.user.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 用户角色(Role)表控制层
 *
 * @author hbx
 * @since 2019-12-30 17:17:24
 */
@Slf4j
@RestController
@RequestMapping("dict")
@Api
@Transactional(rollbackFor = Exception.class)
@Validated
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class DictController extends BaseController<DictService,Dict,String> implements DictFeign {

    /**
     * 字典数据
     */
    private final DictDataService dictDataService;




    @ApiOperation(value = "删除字典以及关联字典数据",notes = "删除字典以及关联字典数据")
    @ApiImplicitParams({
    	@ApiImplicitParam(name="id",value = "id"),
    })
    @GetMapping("delete_dict/{id}")
    @Override
    public R deleteDict(@PathVariable String id) {
        boolean removeDictData = dictDataService.remove(Wrappers.<DictData>lambdaQuery().eq(DictData::getDictId, id));
        if(!removeDictData){
            return failed("删除字典失败,关联字典数据出错!");
        }
        return result(Boolean::booleanValue,this.service.removeById(id),"删除字典失败");
    }


}
